const mysql = require('mysql')

// 数据库配置
const dbset = {
	host: "ip",
	user: "xx",
	password: "xxxx",
	port: "xxxx",
	database: "giftseckill" 

}

const db = mysql.createConnection(dbset);

var addUser = (user)=>{
 	var sql = "insert into user set ?";
	return new Promise((resolve,reject)=>{
		db.query(sql,user,(error,rows)=>{
			if(error != null){
				console.log(error);
				resolve(false);	
			} else{
				resolve(true);
			}
		})
	})
}

var queryUser = (user_id)=>{
	var sql = "select * from user where user_id = ? "
	return new Promise((resolve,reject)=>{
		db.query(sql,user_id,function (error,results,fields){
			if(error) throw error;
			if(results.length == 0 ){
				resolve(false)
			}else{
				resolve(true)				
			}
		})
	}) 
}



//导出
exports.addUser_ = addUser;
exports.existUser_ = queryUser;